<?php

class saveRbtModerateNewAction extends sfActions
{
	public function executeSaveRbtModerateNew()
	{
		$this->setLayout('popup');
  	
	  	//save ringBackTone information
	  	$ringtoneId = $this->getRequestParameter('id');
	  	$ringtone = $this->getRequestParameter('ringtone');	  	
	  	
	  	$rt = new Ringtone();
	  	$rt->setId($ringtoneId);
	  	
	  	$rt_extra = new RingtoneExtra();
	  	$rt_extra->setRingtoneId($ringtoneId);
	  	
	  	if (isset($ringtone['name']))
	    {
	      $rt->setName($ringtone['name']);
	    }
	          	
	  	if (!isset($ringtone['composed_by_user']))
		{
			$ringtone['composed_by_user'] = 0;
		}
		
	    if (isset($ringtone['rbt_id']))
		{
			$rt_extra->setRbtCode($ringtone['rbt_id']);
			$rt_extra->setRbtId($ringtone['rbt_id']);
		}
			
	    if (isset($ringtone['description']))
	    {
	    	$rt_extra->setDescription(trim($ringtone['description']));
	    }
	    
	    if (isset($ringtone['avatar_path']))
	    {
	    	$rt->setAvatarPath($ringtone['avatar_path']);
	    }
	    
	    if (isset($ringtone['file_path_mp3']))
	    {
	    	$rt->setFilePathMp3($ringtone['file_path_mp3']);
	    }
	    
	    if (isset($ringtone['file_path_wav']))
	    {
	    	$rt->setFilePathWav($ringtone['file_path_wav']);
	    }
	        
	    if (isset($ringtone['duration']))
	    {
	    	$rt->setDuration($ringtone['duration']);
	    }
	    
	    
	    if (isset($ringtone['category_id']))
	    {
	    	$rt->setCategoryId($ringtone['category_id'] ? $ringtone['category_id'] : null);
	    }
	    
	    //sfContext::getInstance()->getLogger()->err('tao log day');	    
	    
	    $rt->setNew(false);    
	    $rt->save();
	    
	    $rt_extra->setNew(false);    
	    $rt_extra->save();
	    
	    $this->ok = true;    
	    return;
	}
}
